var http = require('http');
var fs = require('fs');

var server = http.createServer();

server.on('request',function (req,res) {
    var url = req.url
    if(url === '/'){
        fs.readFile('E:/xuexiWrokPlace/nodeXuexi/apache/index.html',function (err,data) {
            if(err){
               return res.end('404 Not Found')
            }
            res.end(data)
        })
    }else if(url !== '/'){
        var filepath = url;
        fs.readFile('E:/xuexiWrokPlace/nodeXuexi/apache/img'+filepath,function (err,data) {
            if(err){
                console.log(err)
                console.log('E:/xuexiWrokPlace/nodeXuexi/apache/img'+filepath)
                return res.end('404 Not Found')
            }
            res.end(data)
        })
    }

})

server.listen(3000,function () {
    console.log('Server is Running ')

})